//
//  AutoEvent.m
//  crashreport
//
//  Created by william on 12-8-8.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "AutoEvent.h"

@implementation AutoEvent

-(id) init
{
    if(self = [super init])
    {
        m_condition = [[NSCondition alloc] init];
        m_semaphor = 0;
    }
    
    return self;
}

-(void) dealloc
{
    [m_condition release], m_condition = nil;
    [super dealloc];
}

-(void) signal
{    
    [m_condition lock];
    m_semaphor ++;
    [m_condition signal];
    [m_condition unlock];
}

-(void) wait
{
    [m_condition lock];
    if(m_semaphor==0){
        [m_condition wait];
    }
    m_semaphor --;
    [m_condition unlock];
}

@end
